C
      SUBROUTINE TRNSIN (IX, IY, NREC, NEL, NDEVIX, NDEVIY, IBAND1,
     .                  IBAND2, XINF, MAX1, MIN1, AVDFSQ, N)
C
C     THIS SUBROUTINE COMPUTES THE AVERAGE INFORMATION TRANSFERRED FROM
C     X TO Y (TRANSINFORMATION)
C
C     ******************************************************************
C
      LOGICAL*1 IX(4,NEL), IY(4,NEL)
      DIMENSION IH(128,128)
      INTEGER OBS, EXP, DIFSQ
      COMMON/PROB/PRBXAY(128,128),PRBX(128),PRBY(128),PRBXGY(128,128),
     .   XMUT(128,128),XINFYI(128)
C
      DO 10 I=1,128
      DO 10 J=1,128
      IH(I,J)=0
   10 CONTINUE
      SUMABS=0.0
      DIFSQ = 0
C
      DO 15 I=1,NREC
      READ(NDEVIX) IX
      READ(NDEVIY) IY
C
      DO 15 J=1,NEL
      L=IX(IBAND1,J)+1
      M=IY(IBAND2,J)+1
      IH(L,M)=IH(L,M)+1
C
      EXP=IX(IBAND1,J)
      OBS=IY(IBAND2,J)
      IF (EXP.EQ.0) GO TO 11
      DIFOEX = (OBS-EXP)/FLOAT(EXP)
      GO TO 12
   11 DIFOEX=OBS
C
   12 SUMABS = SUMABS+ABS(DIFOEX)
      DIFSQ = DIFSQ+(OBS-EXP)**2
   15 CONTINUE
C
      N = NREC*NEL
      AVPDEV = 100.0*SUMABS/N
      AVDFSQ = FLOAT(DIFSQ)/N
C
C     FIND THE RANGE OF THE DATA (MIN TO MAX)
      DO 16 NR=1,128
      DO 16 J=NR,128
      IF (IH(J,NR).NE.0) GO TO 17
      IF (IH(NR,J).NE.0) GO TO 17
   16 CONTINUE
   17 MIN = NR-1
      DO 18 NR1=1,128
      NR = 129-NR1
      DO 18 J=1,NR
      IF (IH(NR,J).NE.0) GO TO 19
      IF (IH(J,NR).NE.0) GO TO 19
   18 CONTINUE
   19 MAX = NR-1
      MAX1=MAX-MIN+1
      MIN1=MIN
C
C     COMPUTE JOINT PROBABILITY OF X AND Y
      DO 20 I=1,MAX1
      DO 20 J=1,MAX1
   20 PRBXAY(I,J) = FLOAT(IH(I+MIN,J+MIN))/N
C
C     COMPUTE MARGINAL PROBABILITY OF X
      DO 25 I=1,MAX1
      PRBX(I)=0.0
   25 CONTINUE
      DO 30 I=1,MAX1
      DO 30 J=1,MAX1
      PRBX(I)=PRBX(I)+PRBXAY(I,J)
   30 CONTINUE
C
C     COMPUTE MARGINAL PROBABILITY OF Y
      DO 35 I=1,MAX1
      PRBY(I)=0.0
   35 CONTINUE
      DO 40 J=1,MAX1
      DO 40 I=1,MAX1
      PRBY(J)=PRBY(J)+PRBXAY(I,J)
   40 CONTINUE
C
C     COMPUTE CONDITIONAL PROBABILITY OF X GIVEN Y
      DO 50 J=1,MAX1
      DO 50 I=1,MAX1
      IF(PRBY(J).LE.0.0) GO TO 45
      PRBXGY(I,J)=PRBXAY(I,J)/PRBY(J)
      GO TO 50
   45 PRBXGY(I,J)=0.0
   50 CONTINUE
C
C     COMPUTE MUTUAL INFORMATION BETWEEN X AND Y
      ALN2=ALOG10(2.0)
      DO 65 I=1,MAX1
      DO 65 J=1,MAX1
      IF(PRBXGY(I,J).LE.0.0) GO TO 60
      IF(PRBX(I).LE.0.0) GO TO 60
      XMUT(I,J)=ALOG10(PRBXGY(I,J)/PRBX(I))/ALN2
      GO TO 65
   60 XMUT(I,J)=0.0
   65 CONTINUE
C
C     COMPUTE AVERAGE INFORMATION TRANSFERRED FROM X TO Y
C     (TRANSINFORMATION)
      XINF=0.0
      DO 85 I=1,MAX1
      DO 85 J=1,MAX1
      XINF=XINF+PRBXAY(I,J)*XMUT(I,J)
   85 CONTINUE
C
C     COMPUTE THE SUMMATION OVER X OF THE CONDITIONAL PROBABILITY OF
C     X GIVEN Y TIMES THE MUTUAL INFORMATION BETWEEN X AND Y
      DO 70 I=1,MAX1
      XINFYI(I)=0.0
   70 CONTINUE
      DO 75 J=1,MAX1
      DO 75 I=1,MAX1
      XINFYI(J)=XINFYI(J)+PRBXGY(I,J)*XMUT(I,J)
   75 CONTINUE
C
      WRITE(6,100) MIN, MAX
      WRITE(6,350) N
      WRITE(6,200) AVPDEV
      WRITE(6,950) IBAND1,XINF
      RETURN
C
  100 FORMAT (/ 1X,'RANGE OF DATA=',I5,2X,'TO',I5)
  200 FORMAT (/ 1X,'AVERAGE PERCENT DEVIATION =',F12.5)
  350 FORMAT (/ 1X,'TOTAL NUMBER OF OCCURRENCES=',I6)
  950 FORMAT (/ 1X,'TRANSINFORMATION FOR BAND',I2,' =',F12.5,
     .   '  BIT/SYMBOL')
      END
